package cc.linker.steplink.crm.commons.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListByFirstUtil {


    public static List<Map<String,String>> toMap( List<Map<String,String>> list){
         List<Map<String,String>> resListMapList = new ArrayList<>();
        if(list!=null && list.size()>0){
            List<Map<String,String>> A = new ArrayList<>();
            List<Map<String,String>> B = new ArrayList<>();
            List<Map<String,String>> C = new ArrayList<>();
            List<Map<String,String>> D = new ArrayList<>();
            List<Map<String,String>> E = new ArrayList<>();
            List<Map<String,String>> F = new ArrayList<>();
            List<Map<String,String>> G = new ArrayList<>();
            List<Map<String,String>> H = new ArrayList<>();
            List<Map<String,String>> I = new ArrayList<>();
            List<Map<String,String>> J = new ArrayList<>();
            List<Map<String,String>> K = new ArrayList<>();
            List<Map<String,String>> L = new ArrayList<>();
            List<Map<String,String>> M = new ArrayList<>();
            List<Map<String,String>> N = new ArrayList<>();
            List<Map<String,String>> O = new ArrayList<>();
            List<Map<String,String>> P = new ArrayList<>();
            List<Map<String,String>> Q = new ArrayList<>();
            List<Map<String,String>> R = new ArrayList<>();
            List<Map<String,String>> S = new ArrayList<>();
            List<Map<String,String>> T = new ArrayList<>();
            List<Map<String,String>> U = new ArrayList<>();
            List<Map<String,String>> V = new ArrayList<>();
            List<Map<String,String>> W = new ArrayList<>();
            List<Map<String,String>> X = new ArrayList<>();
            List<Map<String,String>> Y = new ArrayList<>();
            List<Map<String,String>> Z = new ArrayList<>();
            List<Map<String,String>> orther = new ArrayList<>();
            for(Map<String,String> info : list){
                String customerName = info.get("customerName");
                if(customerName.length()>1){
                    customerName = customerName.substring(0,1);
                }
                String first = "";
                try {
                    first =ChinessFirst.converterToFirstSpell(customerName);
                    if(first.length()>1){
                        first = first.substring(0,1);
                    }
                    first = first.toUpperCase();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                switch (first){
                    case "A" : A.add(info);
                        break;
                    case "B" : B.add(info);
                        break;
                    case "C" : C.add(info);
                        break;
                    case "D" : D.add(info);
                        break;
                    case "E" : E.add(info);
                        break;
                    case "F" : F.add(info);
                        break;
                    case "G" : G.add(info);
                        break;
                    case "I" : I.add(info);
                        break;
                    case "H" : H.add(info);
                        break;
                    case "J" : J.add(info);
                        break;
                    case "K" : K.add(info);
                        break;
                    case "L" : L.add(info);
                        break;
                    case "M" : M.add(info);
                        break;
                    case "N" : N.add(info);
                        break;
                    case "O" : O.add(info);
                        break;
                    case "P" : P.add(info);
                        break;
                    case "Q" : Q.add(info);
                        break;
                    case "R" : R.add(info);
                        break;
                    case "S" : S.add(info);
                        break;
                    case "T" : T.add(info);
                        break;
                    case "U" : U.add(info);
                        break;
                    case "V" : V.add(info);
                        break;
                    case "W" : W.add(info);
                        break;
                    case "X" : X.add(info);
                        break;
                    case "Y" : Y.add(info);
                        break;
                    case "Z" : Z.add(info);
                        break;
                    default: orther.add(info);
                        break;
                }
            }
            if(A.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",A);
                resMap.put("key","A");
                resListMapList.add(resMap);
            }
            if(B.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",B);
                resMap.put("key","B");
                resListMapList.add(resMap);
            }
            if(C.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",C);
                resMap.put("key","C");
                resListMapList.add(resMap);
            }
            if(D.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",D);
                resMap.put("key","D");
                resListMapList.add(resMap);
            }
            if(E.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",E);
                resMap.put("key","E");
                resListMapList.add(resMap);
            }
            if(F.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",F);
                resMap.put("key","F");
                resListMapList.add(resMap);
            }
            if(G.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",G);
                resMap.put("key","G");
                resListMapList.add(resMap);
            }
            if(H.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",H);
                resMap.put("key","H");
                resListMapList.add(resMap);
            }
            if(I.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",I);
                resMap.put("key","I");
                resListMapList.add(resMap);
            }
            if(J.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",J);
                resMap.put("key","J");
                resListMapList.add(resMap);
            }
            if(K.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",K);
                resMap.put("key","K");
                resListMapList.add(resMap);
            }
            if(L.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",L);
                resMap.put("key","L");
                resListMapList.add(resMap);
            }
            if(M.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",M);
                resMap.put("key","M");
                resListMapList.add(resMap);
            }
            if(N.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",N);
                resMap.put("key","N");
                resListMapList.add(resMap);
            }
            if(O.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",O);
                resMap.put("key","O");
                resListMapList.add(resMap);
            }
            if(P.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",P);
                resMap.put("key","P");
                resListMapList.add(resMap);
            }
            if(Q.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",Q);
                resMap.put("key","Q");
                resListMapList.add(resMap);
            }
            if(R.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",R);
                resMap.put("key","R");
                resListMapList.add(resMap);
            }
            if(S.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",S);
                resMap.put("key","S");
                resListMapList.add(resMap);
            }
            if(T.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",T);
                resMap.put("key","T");
                resListMapList.add(resMap);
            }
            if(U.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",U);
                resMap.put("key","U");
                resListMapList.add(resMap);
            }
            if(V.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",V);
                resMap.put("key","V");
                resListMapList.add(resMap);
            }
            if(W.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",W);
                resMap.put("key","W");
                resListMapList.add(resMap);
            }
            if(X.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",X);
                resMap.put("key","X");
                resListMapList.add(resMap);
            }
            if(Y.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",Y);
                resMap.put("key","Y");
                resListMapList.add(resMap);
            }
            if(Z.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",Z);
                resMap.put("key","Z");
                resListMapList.add(resMap);
            }
            if(orther.size()>0){
                Map resMap = new HashMap();
                resMap.put("list",orther);
                resMap.put("key","#");
                resListMapList.add(resMap);
            }
        }
        return resListMapList;
    }
}
